import { verCode} from '@/api/login.js'
export default {
  namespaced: true,
  state: {
    t: '',
    key: '',
    salt: '',
    iv: '',
    loginLoading:false
  },
  getters:{
    
  },
  mutations: {
    setInfo (state,info) {
        for(let key in info){
            state[key] = info[key]
        }
    },
    setLoginLoading(state,val){
      state.loginLoading = val
    }
  },
  actions: {
    async verification({ commit }) {
        commit('setLoginLoading',false)
        let {data:{code,data}} = await verCode();
        if (code === 1) {
            const t = data['t'];
            let codeArr = Object.values(data);
            codeArr.sort();
            const key = codeArr[0];
            const salt = codeArr[1];
            const iv = codeArr[2];
            commit('setInfo',{
                t,
                key,
                salt,
                iv
            })
            return data;
        } else {
            commit('setInfo',{
                t:'',
                key:'',
                salt:'',
                iv:''
            })
            // this.$Message.error(message)
        }
    }
  }
}
